﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if NETFX_CORE
using Windows.Foundation;

#endif

namespace StyleMVVM.Validation.Impl.Method
{
	public class AsyncValidationMethodRule<T> : BaseMethodRule<T>, IAsyncValidationRule
	{
		private IEnumerable<string> standards;
		private IEnumerable<string> dependentProperties;
		private readonly Func<IRuleExecutionContext<T>, Task> asyncMethod;

		public AsyncValidationMethodRule(Func<IRuleExecutionContext<T>, Task> asyncMethod,
		                                 string name,
		                                 IEnumerable<string> standards,
		                                 IEnumerable<string> dependentProperties)
			: base(name, standards, dependentProperties)
		{
			this.asyncMethod = asyncMethod;
		}

#if NETFX_CORE
		public IAsyncAction Validate(IRuleExecutionContext context)
		{
			RuleExecutionContext<T> ruleExecutionContext = new RuleExecutionContext<T>(context);

			return asyncMethod(ruleExecutionContext).AsAsyncAction();
		}
#else
		public Task Validate(IRuleExecutionContext context)
		{
			RuleExecutionContext<T> ruleExecutionContext = new RuleExecutionContext<T>(context);

			return asyncMethod(ruleExecutionContext);
		}
#endif
	}
}